import React from 'react';
import { Popover, Button, message } from 'antd';
import axios from '../../utils/http';
class PopoverBtn extends React.Component {
  state = {
    visible: false,
  };

  hide = () => {
    console.log(this.props.item);
    axios({
      url: '/mm-goods/goods/delGoodsClass',
      params: {
        goodsCid: this.props.item.goods_cid,
        goodPid: this.props.item.good_pid,
      },
    }).then(({ data }) => {
      if (data.code === 400) {
        message.error('该分类下存在子级，请先删除全部子级！');
      }
      if (data.code === 200) {
        message.success('删除成功');
        this.setState({
          visible: false,
        });
      }
    });
  };

  handleVisibleChange = visible => {
    this.setState({ visible });
  };
  render() {
    return (
      <>
        <Popover
          content={
            <div style={{ textAlign: 'center' }}>
              <p style={{ color: '#eb4d4b' }}>确认删除吗？</p>
              <Button type="primary" onClick={this.hide}>
                OK
              </Button>
            </div>
          }
          trigger="click"
          visible={this.state.visible}
          onVisibleChange={this.handleVisibleChange}
        >
          <Button type="link">删除</Button>
        </Popover>
      </>
    );
  }
}
export default PopoverBtn;
